package com.dzx.scala.dzxbootscala.controller;

import com.dzx.scala.dzxbootscala.entity.MetaDatabase;
import com.dzx.scala.dzxbootscala.entity.ResultVO;
import com.dzx.scala.dzxbootscala.service.MetaDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DuanZhaoXu
 * @ClassName:
 * @Description:
 * @date 2018年12月20日 17:02:57
 */
@RestController
@RequestMapping("/meta/database")
public class MetaDatabaseController {


    @Autowired
    private MetaDatabaseService metaDatabaseService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResultVO save(@ModelAttribute MetaDatabase metaDatabase) {
        metaDatabaseService.save(metaDatabase);
        return ResultVO.success();
    }

    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ResultVO query() {
        return ResultVO.success(metaDatabaseService.query());
    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultVO update(@ModelAttribute MetaDatabase metaDatabase) {
        //  return ResultVO.success(metaDatabaseService.update(metaDatabase););
        if (metaDatabase.getId() != null) {
            metaDatabaseService.save(metaDatabase);
            return ResultVO.success();
        } else {
            return ResultVO.error(1, "id不能为空");
        }
    }

    @RequestMapping(value = "/deleteById",method = RequestMethod.GET)
    public ResultVO delete(Integer id) {
        metaDatabaseService.delete(id);
        return ResultVO.success();
    }


}
